package com.sit.controller;

import com.sit.entity.AddAthlete;
import com.sit.service.AddAthleteService;
import com.sit.service.CaService;
import com.sit.vo.DataVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller//直接返回json格式的数据
public class CaController {
    @Autowired
    private CaService caService;

    @Autowired
    private AddAthleteService addAthleteService;

    @ResponseBody
    @RequestMapping("/calist")
    public DataVO calist(Integer page,Integer limit){
        return caService.findData(page,limit);
    }

    @ResponseBody
    @PostMapping("/addAthlete")
    public boolean addAthlete(AddAthlete addAthlete){
       return addAthleteService.addAthlete(addAthlete);
    }

    @ResponseBody
    @PostMapping("/deleteAthlete")
    public boolean deleteAthlete(@RequestParam("ano")String ano,@RequestParam("cnoA")String cnoA){
        return caService.deleteAthlete(ano,cnoA);
    }

    @ResponseBody
    @PostMapping("/updateAthlete")
    public boolean updateAthlete(AddAthlete addAthlete,@RequestParam("cnA_new")String cnA_new){
        return caService.updateAthlete(addAthlete,cnA_new);
    }

    @ResponseBody
    @RequestMapping("/searchAthlete")
    public DataVO searchAthlete(@RequestParam("ano")String ano,@RequestParam("cnA")String cnA, @RequestParam("page")Integer page,@RequestParam("limit")Integer limit){
        return caService.search(ano,cnA,page,limit);
    }

    @ResponseBody
    @PostMapping("/editScore")
    public boolean editScore(@RequestParam("ano")String ano,@RequestParam("cnA")String cnoA,
                             @RequestParam("rank")Integer rank,@RequestParam("score")String score){
        return caService.editScore(ano, cnoA, rank, score);
    }
}
